﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vehicle;

namespace _7_2_Class
{
    public interface ITestInterface
    {
        
        void TestFunc();
    }

    public interface ITestInterface1
    {
        string TestString();
    }

    public class Test : ITestInterface, ITestInterface1
    {
        public void TestFunc()
        {
            throw new NotImplementedException();
        }

        public string TestString()
        {
            throw new NotImplementedException();
        }
    }
    public class TestBaseClass
    {
        public int ti;
        private float tf;
        protected string ts;

        public virtual void Print()
        {

        }
    }
    public abstract class BaseClass
    {
        protected int testIII;
        public void TestFunc()
        {
            Console.WriteLine("BaseClass TestFunc");
        }

        public abstract void AbstractFunc();

        public virtual string Print()
        {
            return "Type :" + GetType();
        }
        /*

        实现交通工具的类层次  
        基类Vehicle     GetVehicleType
        子类汽车 Car -> Compact小汽车  SUV  Pickup货车  各种具体型号的车子
        子类火车 Train ->  PassengerTrain 客运火车  FreightTrain货运火车  _424DoubleDogey 特殊的火车可以拉货和载客...


        Compact小汽车 SUV PassengerTrain _424DoubleDogey 都可以载客 实现拉客接口IPassengerCarrier  GetPassengerCarrier 获取了载客人数
        Pickup货车 FreightTrain货运火车 _424DoubleDogey 都可以拉货   实现拉货接口IHeavyLoadCarrier GetHeavyLoadCarrier 获取了运输吨数

            */
    }

    public interface IPoint
    {
        float X
        {
            set;
            get;
        }

        float Y
        {
            set;
            get;
        }
    }

    public class Vec2 : BaseClass //, IPoint
    {
        private float x;
        private float y;

        
        public float X
        {
            
            set
            {
                if (x == value)
                    return;

                Console.WriteLine("old:"+ x + " new:" + value);
                x = value;

            }
            get { return x; }
            
            /*
            set;
            get;
            */
            /*
            get;
            */

             //get;
             //private set;
        }

        public float Y
        {
            get
            {
                throw new NotImplementedException();
            }

            set
            {
                throw new NotImplementedException();
            }
        }

        /*
        public float X
        {
            set
            {
                if (value < 0)
                    this.x = 0;
                else
                    this.x = value;
            }
            get { return x; }
        }

        public float Y
        {
            set
            {
                if (value < 0)
                    this.y = 0;
                else
                    this.y = value;
            }
            get { return y; }
        }

            */
        public void SetXY(float x, float y)
        {
            this.x = x;
            this.y = y;
        }

        public void SetX(float x)
        {
            this.x = x;
        }

        public void SetY(float y)
        {
            this.y = y;
        }

        public float GetX()
        {
            return x;
        }

        public float GetY()
        {
            return y;
        }


        public new void TestFunc()
        {
            Console.WriteLine("Vec2 TestFunc");
        }

        /*
        public override string Print()
        {
            return "Vec2 x:" + x + " y:" + y;
        }

    */
        public override string Print()
        {
            return "Vec2 x:" + x + " y:" + y;
        }

        public override bool Equals(object obj)
        {
            return x == ((Vec2)obj).x && y == ((Vec2)obj).y;
        }

        public override void AbstractFunc()
        {
            Console.WriteLine("AbstractFunc");
        }
    }

    public class Vec2Test : Vec2
    {
        private int t;
        public override bool Equals(object obj)
        {
            return base.Equals(obj) && t == ((Vec2Test)obj).t;
        }

        public override string Print()
        {
            return base.Print() + " t:" + t;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            VehicleDataBase vdb = new VehicleDataBase();
            /*
            vdb.AddVehicle(new SUV());
            vdb.AddVehicle(new PassengerTrain());

            vdb.AddPassenger(new Compact());
            */
            vdb.AddHeavyLoad(new _424DoubleDogey());


            Console.ReadKey();

            Vec2 v2 = new Vec2();

            Console.WriteLine(v2.X);

            Console.WriteLine(v2.Print());

            //v2.Y = -123;
            Console.WriteLine(v2.Print());

            v2.SetXY(1, 2);

            Console.WriteLine(v2.Print());

            Vec2 v3 = new Vec2();
            //v3.X = 1;
            //v3.Y = 2;
            Console.WriteLine(v3.Print());
            if (v2.Equals(v3)) // ==
                Console.WriteLine("==");
            else
                Console.WriteLine("!=");

            Vec2Test v2t = new Vec2Test();
            v2t.SetXY(12, 34);
            Vec2Test v3t = new Vec2Test();
            v3t.SetXY(12, 34);

            v2.TestFunc();
            v2t.TestFunc();

            v2.AbstractFunc();
            v2t.AbstractFunc();

            Console.WriteLine(v2t.Print());
            Console.WriteLine(v3t.Print());

            if (v2t.Equals(v3t)) // ==
                Console.WriteLine("==");
            else
                Console.WriteLine("!=");

            Console.ReadKey();
        }
    }
}
